package com.shop.front.dao.store;


import com.shop.jpa.BaseSQLDao;
import com.shop.jpa.support.QuerySQL;
import com.shop.front.vo.store.StoreOrderCartInfoVo;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class StoreOrderCartInfoSQLDao extends BaseSQLDao {


    public List<StoreOrderCartInfoVo> orderCartInfoList(Long orderId) {
        String field = "spav.image, spav.suk, sp.store_name, soci.*";
        String from = "t_store_order_cart_info soci left join t_store_product sp on soci.product_id = sp.id left join t_store_product_attr_value spav on soci.product_attr_value_id = spav.id";
        String order = "soci.id desc";

        QuerySQL qs = new QuerySQL(field, from, order);
        qs.addWhereWithoutParams("soci.is_deleted = 0 and sp.is_deleted = 0 and spav.is_deleted = 0");
        qs.addWhereEq("soci.oid", orderId);

        return this.query(qs, StoreOrderCartInfoVo.class);
    }

    public StoreOrderCartInfoVo orderCartInfoObj(Long orderId) {
        String field = "spav.image, spav.suk, sp.store_name, soci.*";
        String from = "t_store_order_cart_info soci left join t_store_product sp on soci.product_id = sp.id left join t_store_product_attr_value spav on soci.product_attr_value_id = spav.id";
        String order = "soci.id desc limit 1";

        QuerySQL qs = new QuerySQL(field, from, order);
        qs.addWhereWithoutParams("soci.is_deleted = 0 and sp.is_deleted = 0 and spav.is_deleted = 0");
        qs.addWhereEq("soci.oid", orderId);

        return this.querySingle(qs, StoreOrderCartInfoVo.class);
    }


}
